import java.util.Arrays;

public class Learn16 {
    public static void bubbleSort(int[] array){
        for (int i = 0; i < array.length-1; i++) {
            boolean flg = true;
            for (int j = 0; j < array.length-i-1;j++){
                if(array[j] >array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    flg = false;
                }
            }
            if(flg == true){
                break;
            }
        }
    }


    public static void main(String[] args) {
        int[] array = {1,2,3,4,5,6};
        bubbleSort(array);                    //冒泡排序实现
//        System.out.println(Arrays.toString(array));
        for (int x:array) {
            System.out.print(x +" ");
        }
    }
}